﻿#region Imports
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using NHibernate.Criterion;

using Project.Common;
using Project.IManager;
using Project.Repository;
using Project.Model;
#endregion

namespace Project.Manager
{

    #region 表名:DPlantable. 描述:
    /// <summary>
    /// DPlantable 业务接口
    /// </summary>
    public interface IDPlantableManager : IManagerBase<DPlantable>
    {
        DPlantable GetByName(string JhType);
    }
    /// <summary>
    /// DPlantable 业务接口方法实现
    /// </summary>
    public class DPlantableManager : AbstractManager<DPlantable>, IDPlantableManager
    {
        public DPlantable GetByName(string JhType)
        {
            //创建查询器
            IList<ICriterion> queryList = new List<ICriterion>();
            //传入条件
            queryList.Add(Restrictions.Eq(PropertyNameHelper.Resolve<DPlantable>(d => d.JhType), JhType));

            IList<DPlantable> list = Dao.GetByCriteria(queryList);

            // 由于测试数据有多条记录,暂时取消记录数必须为一条的限制,只取第一条记录
            //if (list != null && list.Count == 1)
            if (list != null && list.Count > 0)
            {
                return list[0];
            }
            else
            {
                return null;
            }

        }

    }
    #endregion

    #region 表名:File. 描述:
    /// <summary>
    /// File 业务接口
    /// </summary>
    public interface IFileManager : IManagerBase<Files>
    {
        Files GetByName(string item_table_id);
   }
    /// <summary>
    /// File 业务接口方法实现
    /// </summary>
    public class FileManager : AbstractManager<Files>, IFileManager
    {
        public Files GetByName(string item_table_id)
        {
            //创建查询器
            IList<ICriterion> queryList = new List<ICriterion>();
            //传入条件
            queryList.Add(Restrictions.Eq(PropertyNameHelper.Resolve<Files>(d => d.Ftitle), item_table_id));
            // 排序字段
            Order order = Order.Desc(PropertyNameHelper.Resolve<Files>(d => d.Fid));

            IList<Files> list = Dao.GetByCriteria(queryList, order);

            // 由于测试数据有多条记录,暂时取消记录数必须为一条的限制,只取第一条记录
            //if (list != null && list.Count == 1)
            if (list != null && list.Count > 0)
            {
                return list[0];
            }
            else
            {
                return null;
            }

        }
    }
    #endregion

    #region 表名:Fndtable. 描述:
    /// <summary>
    /// Fndtable 业务接口
    /// </summary>
    public interface IFndtableManager : IManagerBase<Fndtable>
    {
    }
    /// <summary>
    /// Fndtable 业务接口方法实现
    /// </summary>
    public class FndtableManager : AbstractManager<Fndtable>, IFndtableManager
    {
    }
    #endregion

    #region 表名:Indexbasictable. 描述:
    /// <summary>
    /// Indexbasictable 业务接口
    /// </summary>
    public interface IIndexbasictableManager : IManagerBase<Indexbasictable>
    {
    }
    /// <summary>
    /// Indexbasictable 业务接口方法实现
    /// </summary>
    public class IndexbasictableManager : AbstractManager<Indexbasictable>, IIndexbasictableManager
    {
    }
    #endregion

    #region 表名:Itemapendix. 描述:
    /// <summary>
    /// Itemapendix 业务接口
    /// </summary>
    public interface IItemapendixManager : IManagerBase<Itemapendix>
    {
    }
    /// <summary>
    /// Itemapendix 业务接口方法实现
    /// </summary>
    public class ItemapendixManager : AbstractManager<Itemapendix>, IItemapendixManager
    {
    }
    #endregion

    #region 表名:Itemembertable. 描述:
    /// <summary>
    /// Itemembertable 业务接口
    /// </summary>
    public interface IItemembertableManager : IManagerBase<Itemembertable>
    {
    }
    /// <summary>
    /// Itemembertable 业务接口方法实现
    /// </summary>
    public class ItemembertableManager : AbstractManager<Itemembertable>, IItemembertableManager
    {
    }
    #endregion

    #region 表名:Itemtable. 描述:
    /// <summary>
    /// Itemtable 业务接口
    /// </summary>
    public interface IItemtableManager : IManagerBase<Itemtable>
    {
        Itemtable GetByItemName(string jhname);

        Itemtable GetByShqUserManager(ShqUserManager ShqUserManager);
    }
    /// <summary>
    /// Itemtable 业务接口方法实现
    /// </summary>
    public class ItemtableManager : AbstractManager<Itemtable>, IItemtableManager
    {
        public Itemtable GetByItemName(string jhname)
        {
            //创建查询器
            IList<ICriterion> queryList = new List<ICriterion>();
            //传入条件
            queryList.Add(Restrictions.Eq(PropertyNameHelper.Resolve<Itemtable>(d => d.Itemname), jhname));

            IList<Itemtable> list = Dao.GetByCriteria(queryList);

            // 由于测试数据有多条记录,暂时取消记录数必须为一条的限制,只取第一条记录
            //if (list != null && list.Count == 1)
            if (list != null && list.Count > 0)
            {
                return list[0];
            }
            else
            {
                return null;
            }

        }
        public Itemtable GetByShqUserManager(ShqUserManager model)
        {
            if (model != null)
            { 
                //创建查询器
                IList<ICriterion> queryList = new List<ICriterion>();
                //传入条件
                queryList.Add(Restrictions.Eq(PropertyNameHelper.Resolve<Itemtable>(d => d.shqid), model.Id.ToString().Trim()));

                IList<Itemtable> list = Dao.GetByCriteria(queryList);

                // 由于测试数据有多条记录,暂时取消记录数必须为一条的限制,只取第一条记录
                //if (list != null && list.Count == 1)
                if (list != null && list.Count > 0)
                {
                    return list[0];
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }

        }
    }
    #endregion

    #region 表名:Plantable. 描述:
    /// <summary>
    /// Plantable 业务接口
    /// </summary>
    public interface IPlantableManager : IManagerBase<Plantable>
    {
        Plantable GetByName(string p);
    }
    /// <summary>
    /// Plantable 业务接口方法实现
    /// </summary>
    public class PlantableManager : AbstractManager<Plantable>, IPlantableManager
    {
        public Plantable GetByName(string jhname)
        {
            //创建查询器
            IList<ICriterion> queryList = new List<ICriterion>();
            //传入条件
            queryList.Add(Restrictions.Eq(PropertyNameHelper.Resolve<Plantable>(d => d.Jhname), jhname));
          
            

            IList<Plantable> list = Dao.GetByCriteria(queryList);

            // 由于测试数据有多条记录,暂时取消记录数必须为一条的限制,只取第一条记录
            //if (list != null && list.Count == 1)
            if (list != null && list.Count > 0)
            {
                return list[0];
            }
            else
            {
                return null;
            }

        }
    }
    #endregion

    #region 表名:Qtzhydw. 描述:
    /// <summary>
    /// Qtzhydw 业务接口
    /// </summary>
    public interface IQtzhydwManager : IManagerBase<Qtzhydw>
    {
    }
    /// <summary>
    /// Qtzhydw 业务接口方法实现
    /// </summary>
    public class QtzhydwManager : AbstractManager<Qtzhydw>, IQtzhydwManager
    {
    }
    #endregion

    #region 表名:ShqUserManager. 描述:
    /// <summary>
    /// ShqUserManager 业务接口
    /// </summary>
    public interface IShqUserManagerManager : IManagerBase<ShqUserManager>
    {
        ShqUserManager GetByUserName(string Itemname);

        ShqUserManager GetByIndexbasictable(Indexbasictable indexbasictable);
    }
    /// <summary>
    /// ShqUserManager 业务接口方法实现
    /// </summary>
    public class ShqUserManagerManager : AbstractManager<ShqUserManager>, IShqUserManagerManager
    {
        public ShqUserManager GetByUserName(string Itemname)
        {
            //创建查询器
            IList<ICriterion> queryList = new List<ICriterion>();
            //传入条件
            queryList.Add(Restrictions.Eq(PropertyNameHelper.Resolve<ShqUserManager>(d => d.Itemname), Itemname));

            IList<ShqUserManager> list = Dao.GetByCriteria(queryList);

            if (list != null && list.Count > 0)
            {
                return list[0];
            }
            else
            {
                return null;
            }

        }
        public ShqUserManager GetByIndexbasictable(Indexbasictable model)
        {
            //创建查询器
            IList<ICriterion> queryList = new List<ICriterion>();
            //传入条件
            queryList.Add(Restrictions.Eq(PropertyNameHelper.Resolve<ShqUserManager>(d => d.Id), int.Parse(model.shqid.Trim())));

            IList<ShqUserManager> list = Dao.GetByCriteria(queryList);

            if (list != null && list.Count > 0)
            {
                return list[0];
            }
            else
            {
                return null;
            }

        }
    }
    #endregion

    #region 表名:ShqryuserManager. 描述:
    /// <summary>
    /// ShqryuserManager 业务接口
    /// </summary>
    public interface IShqryuserManagerManager : IManagerBase<ShqryuserManager>
    {
    }
    /// <summary>
    /// ShqryuserManager 业务接口方法实现
    /// </summary>
    public class ShqryuserManagerManager : AbstractManager<ShqryuserManager>, IShqryuserManagerManager
    {
    }
    #endregion

    #region 表名:UserManager. 描述:
    /// <summary>
    /// UserManager 业务接口
    /// </summary>
    public interface IUserManagerManager : IManagerBase<UserManager>
    {
        /// <summary>
        /// 退出
        /// </summary>
        void SignOut();
        /// <summary>
        /// 登录
        /// </summary>
        void SetAuthCookie(string email, bool createPersistentCookie);
        /// <summary>
        /// 加密
        /// </summary>
        string HashPasswordForStoringInConfigFile(string password);
        /// <summary>
        /// 用户登录验证
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="IsRememberMe">是否记住我</param>
        /// <returns>true:正确.false:错误</returns>
        bool Authenticate(string userName, string password, bool IsRememberMe);

        UserManager GetByUserName(string UserName);

    }
    /// <summary>
    /// UserManager 业务接口方法实现
    /// </summary>
    public class UserManagerManager : AbstractManager<UserManager>, IUserManagerManager
    {
        public virtual void SignOut()
        {
            FormsAuthentication.SignOut();
        }

        public virtual void SetAuthCookie(string email, bool createPersistentCookie)
        {
            FormsAuthentication.SetAuthCookie(email, createPersistentCookie);
        }

        public virtual string HashPasswordForStoringInConfigFile(string password)
        {
            return FormsAuthentication.HashPasswordForStoringInConfigFile(password, "SHA1");
        }

        /// <summary>
        /// 用户登录验证
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="IsRememberMe">是否记住我</param>
        /// <returns>true:正确.false:错误</returns>
        public virtual bool Authenticate(string userName, string password, bool IsRememberMe)
        {
            // 不能用此方法,此方法需要配置web.config中的证书(不知如何配置)
            //return FormsAuthentication.Authenticate(userName,password);
            // 根据用户名查找用户表,之后验证密码是否一致
            UserManager user = this.GetByUserName(userName);
            //if (user != null && user.UserPass == this.HashPasswordForStoringInConfigFile(password))
            if (user != null && user.UserPass == password)
            {
                // 设置登录信息
                this.SetAuthCookie(userName, IsRememberMe);
                return true;
            }
            else
            {
                return false;
            }
        }
        
        public UserManager GetByUserName(string UserName)
        {
            //创建查询器
            IList<ICriterion> queryList = new List<ICriterion>();
            //传入条件
            queryList.Add(Restrictions.Eq(PropertyNameHelper.Resolve<UserManager>(d => d.USERNAME), UserName));

            IList<UserManager> list = Dao.GetByCriteria(queryList);

            if (list != null && list.Count == 1)
            {
                return list[0];
            }
            else
            {
                return null;
            }

        }
    }
    #endregion

    #region 表名:UserNameFj. 描述:
    /// <summary>
    /// UserNameFj 业务接口
    /// </summary>
    public interface IUserNameFjManager : IManagerBase<UserNameFj>
    {
        UserNameFj GetByUserName(string UserName);
    }
    /// <summary>
    /// UserNameFj 业务接口方法实现
    /// </summary>
    public class UserNameFjManager : AbstractManager<UserNameFj>, IUserNameFjManager
    {
        public UserNameFj GetByUserName(string UserName)
        {
            //创建查询器
            IList<ICriterion> queryList = new List<ICriterion>();
            //传入条件
            queryList.Add(Restrictions.Eq(PropertyNameHelper.Resolve<UserNameFj>(d => d.USERNAME), UserName));

            IList<UserNameFj> list = Dao.GetByCriteria(queryList);

            if (list != null && list.Count == 1)
            {
                return list[0];
            }
            else
            {
                return null;
            }

        }
    }
    #endregion

    #region 表名:HTTable. 描述:
    /// <summary>
    /// HTTable 业务接口
    /// </summary>
    public interface IHTTableManager : IManagerBase<HTTable>
    {
        HTTable GetByItemId(string UserName);
    }
    /// <summary>
    /// HTTable 业务接口方法实现
    /// </summary>
    public class HTTableManager : AbstractManager<HTTable>, IHTTableManager
    {
        public HTTable GetByItemId(string Itemid)
        {
            //创建查询器
            IList<ICriterion> queryList = new List<ICriterion>();
            //传入条件
            queryList.Add(Restrictions.Eq(PropertyNameHelper.Resolve<HTTable>(d => d.Itemid), Itemid));

            IList<HTTable> list = Dao.GetByCriteria(queryList);

            if (list != null && list.Count == 1)
            {
                return list[0];
            }
            else
            {
                return null;
            }

        }
    }
    #endregion

    #region 表名:JFYSTtable. 描述:
    /// <summary>
    /// JFYSTtable 业务接口
    /// </summary>
    public interface IJFYSTtableManager : IManagerBase<JFYSTtable>
    {
        JFYSTtable GetByItemId(string UserName);
    }
    /// <summary>
    /// JFYSTtable 业务接口方法实现
    /// </summary>
    public class JFYSTtableManager : AbstractManager<JFYSTtable>, IJFYSTtableManager
    {
        public JFYSTtable GetByItemId(string Itemid)
        {
            //创建查询器
            IList<ICriterion> queryList = new List<ICriterion>();
            //传入条件
            queryList.Add(Restrictions.Eq(PropertyNameHelper.Resolve<JFYSTtable>(d => d.Itemid), Itemid));

            IList<JFYSTtable> list = Dao.GetByCriteria(queryList);

            if (list != null && list.Count == 1)
            {
                return list[0];
            }
            else
            {
                return null;
            }

        }
    }
    #endregion

    #region 表名:RwsBas. 描述:
    /// <summary>
    /// RwsBas 业务接口
    /// </summary>
    public interface IRwsBasManager : IManagerBase<RwsBas>
    {
        RwsBas GetByShqid(string UserName);
    }
    /// <summary>
    /// RwsBas 业务接口方法实现
    /// </summary>
    public class RwsBasManager : AbstractManager<RwsBas>, IRwsBasManager
    {
        public RwsBas GetByShqid(string Shqid)
        {
            //创建查询器
            IList<ICriterion> queryList = new List<ICriterion>();
            //传入条件
            queryList.Add(Restrictions.Eq(PropertyNameHelper.Resolve<RwsBas>(d => d.Shqid), Shqid));

            IList<RwsBas> list = Dao.GetByCriteria(queryList);

            if (list != null && list.Count == 1)
            {
                return list[0];
            }
            else
            {
                return null;
            }

        }
    }
    #endregion

}
